from lib2to3.pgen2 import driver
from selenium import webdriver
from time import sleep
from selenium.common.exceptions import NoSuchElementException

# ## 隐式等待
# driver = webdriver.Chrome()
# driver.implicitly_wait(10)
# driver.get("https://www.baidu.com")
# # 通过id名   #ID名称
# driver.find_element("css selector", "#kw").send_keys("新闻热点")

# # 通过class名   .class名称
# driver.find_element("css selector", ".s_btn").click()
# try:
#     driver.find_element('partial link text', '网易').click()
# except NoSuchElementException as e:
#     print("网络不给力")

# sleep(3)
# driver.quit()



### 显式等待
#引入WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait
#引入expected_conditions类，并重命名为EC
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
# 判断标题是否为“百度一下，你就知道”
title = EC.title_is("百度一下，你就知道")(driver)
# 判断一下标题是否包含“你就”
title2 = EC.title_contains("你就")(driver)
print(title)
print(title2)
driver.find_element("id", "kw").send_keys("赵丽颖")
driver.find_element("id", "su").click()
WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located(("partial link text", "百度百科")), "啦啦啦拉拉阿拉").click()
